package package004.section002

import fundation.gsonPrintln
import org.junit.Test

/**
 * @author futao
 * Created on 2017/11/16 - 14:03.
 */
class Address {
    var country: String
    var province: String
    var city: String

    constructor(country: String, province: String, city: String) {
        this.country = country
        this.province = province
        this.city = city
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as Address

        if (country != other.country) return false
        if (province != other.province) return false
        if (city != other.city) return false

        return true
    }

    override fun hashCode(): Int {
        var result = country.hashCode()
        result = 31 * result + province.hashCode()
        result = 31 * result + city.hashCode()
        return result
    }
}
data class MyAddress(val country: String,val province: String,val city: String)


class HashCode {
    @Test
    fun testCase001() {
        val address = Address("China", "JiangXi", "NanChang")
        val hashSetOf = hashSetOf(address)
        gsonPrintln(hashSetOf.contains(Address("China", "JiangXi", "NanChang")))
        gsonPrintln(hashSetOf.contains(address))
        gsonPrintln(address.hashCode())
        gsonPrintln(Address("China", "JiangXi", "NanChang").hashCode())

    }
    @Test
    fun testCase002(){
        val address=MyAddress("China","江西","南昌")
        val address2=MyAddress("China","江西","南昌")
        gsonPrintln(address.equals(address2))
        gsonPrintln(address.toString())
        gsonPrintln(address)
        val address3=address.copy(province = "11")

        println(address.toString())
        println(address)
    }
}